<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="反馈用户" prop="userId">
                <el-select
                  v-model="queryParams.userId"
                  placeholder="请选择"
                  class="w-200"
                  filterable
                >
                  <el-option
                    v-for="item in userList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="处理状态" prop="suggestStatus">
                <el-select
                  v-model="queryParams.suggestStatus"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in suggestStatusList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="投诉类型" prop="suggestType">
                <el-select
                  v-model="queryParams.suggestType"
                  placeholder="请选择"
                  class="w-200"
                >
                  <el-option
                    v-for="item in suggestTypeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <!-- 会员卡列表 -->
    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">投诉建议</div>
      </div>

      <div class="table_list">
        <el-table :data="suggestionsLists" stripe style="width: 100%">
          <el-table-column
            prop="custName"
            label="投诉人姓名"
            width="140px"
          ></el-table-column>
          <el-table-column
            prop="suggestDesc"
            label="投诉描述"
          ></el-table-column>
          <el-table-column prop="suggestLinkMobile" label="投诉联系电话">
          </el-table-column>
          <el-table-column prop="suggestLinkName" label="投诉联系姓名">
          </el-table-column>
          <el-table-column prop="suggestResult" label="处理结果">
          </el-table-column>
          <el-table-column prop="suggestStatusStr" label="处理状态">
          </el-table-column>
          <el-table-column prop="suggestTypeStr" label="投诉类型">
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间">
          </el-table-column>
          <el-table-column prop="date" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="Takedown(scope.row)">{{
                scope.row.suggestStatus !== "F" ? "处理反馈" : "查看详情"
              }}</el-button>

              <!-- <el-button
                  size="mini"
                  type="text"
                  :disabled="scope.row.crossStatus === 'N' ? true : false"
                  @click="Takedown(scope.row, 'N')"
                  >不计算</el-button
                > -->
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>

    <el-dialog
      title="处理反馈"
      :visible.sync="HandleFeedback"
      width="600px"
      :before-close="HandleFeedbackClose"
    >
      <span>
        <div>
          <el-descriptions title="处理反馈" :column="2" :size="'small'" border>
            <el-descriptions-item label="投诉类型">{{
              SuggestInfo.suggestTypeStr
            }}</el-descriptions-item>
            <el-descriptions-item label="投诉描述">{{
              SuggestInfo.suggestDesc
            }}</el-descriptions-item>
            <el-descriptions-item label="姓名">{{
              SuggestInfo.suggestLinkName
            }}</el-descriptions-item>
            <el-descriptions-item label="电话">{{
              SuggestInfo.suggestLinkMobile
            }}</el-descriptions-item>
            <el-descriptions-item label="附件" :span="2">
              <div v-for="(item, index) in SuggestInfo.fileList" :key="index">
                <div @click="Open(item)" style="cursor: pointer">
                  {{ item.fileName }}
                </div>
              </div>
            </el-descriptions-item>
            <el-descriptions-item
              label="处理结果"
              v-if="suggestStatus === 'F'"
              :span="2"
            >
              <div>{{ SuggestInfo.suggestResult }}</div>
            </el-descriptions-item>
          </el-descriptions>
        </div>
        <div class="Result" v-if="suggestStatus !== 'F'">
          <el-form
            :model="ruleForm"
            :rules="ruleRules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="处理结果" prop="suggestResult">
              <!-- <el-select v-model="ruleForm.suggestResult" placeholder="请选择">
                <el-option
                  v-for="item in suggestStatusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select> -->

               <el-input
                type="textarea"
                placeholder="请输入内容"
                v-model="ruleForm.suggestResult"
                maxlength="50"
                show-word-limit
              >
                             
              </el-input>
            </el-form-item>
          </el-form>
        </div>
      </span>
      <span slot="footer" class="dialog-footer">
        <div v-if="suggestStatus !== 'F'">
          <el-button @click="HandleFeedbackClose">取 消</el-button>
          <el-button type="primary" @click="HandleFeedbackSubmit"
            >确 定</el-button
          >
        </div>
      </span>
    </el-dialog>
    <file-preView ref="FilePreView"></file-preView>
  </div>
</template>

<script>
import {
  getSuggestPage,
  getSuggestInfo,
  HandleFeedback,
} from "@/api/bpm/suggestions";
import { getClientList } from "@/api/business/client";
import FilePreView from "@/components/FilePreView/FilePreView";
export default {
  name: "EryuoaStoreFrontendtabList",
  components: { FilePreView },
  data() {
    return {
      HandleFeedback: false, // 处理反馈
      ruleForm: {
        suggestResult: "",
      },
      ruleRules: {
        suggestResult: [{ required: true, message: "请输入处理意见" }],
      },
      loading: false,
      SuggestTypeLoading: false,
      activeIndex: 1,
      currentIndex: 1,
      suggestionsLists: [], // 项目列表数据
      StoreSlist: [], // 门店列表数据
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        suggestStatus: "",
        suggestType: "",
        userId: "",
      },
      total: 0,
      textarea: "",
      value1: "",

      suggestStatusList: [
        {
          value: "W",
          label: "处理中",
        },
        {
          value: "F",
          label: "已处理",
        },
      ],

      suggestTypeList: [
        {
          value: "BUG",
          label: "系统BUG",
        },
        {
          value: "technician",
          label: "技师投诉",
        },
        {
          value: "store",
          label: "门店投诉",
        },
      ],

      // 销售状态
      saleStatusObj: {
        0: "上架",
        1: "下架",
      },

      ProjrctOptions: [
        {
          value: "0",
          label: "上架",
        },
        {
          value: "1",
          label: "下架",
        },
      ],

      storesList: [], // 应用门店
      storesLoading: false,
      queryParam: {
        pageNo: 1,
        pageSize: 10,
      },
      userList: [],
      SuggestInfo: {},
      suggestId: "",
      suggestStatus: "",
    };
  },

  created() {
    this.getList();
    this.getUser();
  },

  mounted() {},

  methods: {
    // 打开新窗口
    Open(item) {
      this.$nextTick(() => {
        this.$refs.FilePreView.open(item);
      });
    },

    HandleFeedbackClose() {
      if (!!this.$refs.ruleForm) {
        this.resetFormData("ruleForm");
      }

      this.$nextTick(() => {
        this.HandleFeedback = false;
      });
    },

    HandleFeedbackSubmit() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          HandleFeedback({
            suggestId: this.suggestId,
            suggestResult: this.ruleForm.suggestResult,
          }).then((Res) => {
            const { code } = Res;
            if (code === 0) {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.getList();
              this.HandleFeedbackClose();
            }
          });
        } else {
        }
      });
    },

    // 获得投诉建议
    getSuggestInfoItem(suggestId) {
      this.loading = true;
      getSuggestInfo({
        id: suggestId,
      })
        .then((res) => {
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.SuggestInfo = data;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    getUser() {
      this.loading = true;
      getClientList(this.queryParam)
        .then((res) => {
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.userList = data.list;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 取消 查看门店
    CancleCheckStore() {
      this.CheckStoresdialogVisible = false;
      this.storesLoading = false;
      this.storesList = [];
    },

    // 确认 查看门店
    CheckStore() {
      this.CheckStoresdialogVisible = false;
      this.storesLoading = false;
      this.storesList = [];
    },
    getList() {
      this.loading = true;
      getSuggestPage(this.queryParams)
        .then((res) => {
          console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.suggestionsLists = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$refs[formName].resetFields();
    },

    // 操作
    Takedown(row) {
      this.HandleFeedback = true;
      this.getSuggestInfoItem(row.suggestId);
      this.suggestId = row.suggestId;
      this.suggestStatus = row.suggestStatus;
    },
  },
};
</script>

<style lang="scss" scoped>
.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.separate_left {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-right: 12px;
}
.separate_right {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-left: 12px;
}

.check {
  font-size: 12px;
  color: #0052d9;
}

.list_Stores {
  height: 200px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
  line-height: 22px;
  .list_Stores_item {
    height: 46px;
    line-height: 46px;
    background: #ffffff;
    padding-left: 47px;
    border-bottom: 1px solid #e7e7e7;
  }
}

.Result {
  margin-top: 20px;
}
</style>
